package com.datx.wallet.config;

import com.exchange.wallet.bitcoin.rpcclient.BitcoinException;
import com.exchange.wallet.bitcoin.rpcclient.BitcoinRPCClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.MalformedURLException;


/**
 * BtcConfig Created with IntelliJ IDEA.
 * User: liulinhui
 * Date: 2018/8/29
 * Time: 20:38
 * Description: BtcConfig
 */
@Configuration
@Slf4j
public class BtcConfig {


    @Bean
    public BitcoinRPCClient setClient(@Value("${coin.rpc}") String uri){
        try {
            log.info("uri={}",uri);
            BitcoinRPCClient client =  new BitcoinRPCClient(uri);
            int blockCount = client.getBlockCount();
            log.info("blockHeight={}",blockCount);
            return client;
        } catch (MalformedURLException e) {
            log.info("init wallet failed");
            e.printStackTrace();
            System.exit(1);
            return null;
        } catch (BitcoinException e) {
            log.info("BitcoinException");
            e.printStackTrace();
            System.exit(1);
            return null;
        }
    }


}